package jmd.construct;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;

import jmd.bean.ClientEntity;

/**
 * 
 * @author Administrator
 * 
 */
public class ConstructImpl implements Construct
{

	private ByteBuffer w_buffer = ByteBuffer.allocate(1024);

	private Charset charset = Charset.forName("UTF-8");

	/**
	 * This function use to construct a protocol. And this protocol is a
	 * string,which is make by ip+fileName + type + color + fillOut Then encode
	 * this string into stream them send it into buffer
	 */
	
	@Override
	public ByteBuffer constructProtocol1()
	{
		String content ="sdagsagsdagsdagsdg";
		w_buffer.clear();
		w_buffer.put(charset.encode(content));
		w_buffer.flip();
		return w_buffer;
	}
	
	
	
	@Override
	public ByteBuffer constructProtocol(ClientEntity clientEnt)
	{
		String content = clientEnt.getIp() + "," + clientEnt.getFileName() + ","
				+ clientEnt.getType() + "," + clientEnt.getColor() + ","
				+ clientEnt.isFillOut() + ";";
		w_buffer.clear();
		w_buffer.put(charset.encode(content));
		w_buffer.flip();
		return w_buffer;
	}
   
}
